package com.shuai.api_platform.manager;

import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 鉴权参数中随机数管理器
 */
//@Component
public class RandomNumManager_bak {

    private static final ReentrantLock lock = new ReentrantLock(false);

    /**
     * 随机数管理集合
     */
    private static volatile ArrayList<Long> randomList;


    /**
     * 验证随机数管理集合中是否包含传入的随机数
     *
     * @param num 待验证的随机数
     * @return Boolean
     */
    public static boolean hasRandom(Long num) {
        return randomList.contains(num);
    }


    /**
     * 将随机数管理器置空
     */
    public static synchronized void setEmpty() {
        lock.lock();
        try {
            randomList.clear(); // help GC
            randomList = new ArrayList<>();
        } finally {
            lock.unlock();
        }
    }


    /**
     * 向集合管理器中新增元素
     */
    public static boolean addMember(Long num) {
        lock.lock();
        try {
            return randomList.add(num);
        } finally {
            lock.unlock();
        }
    }
}
